Module-level declarations

Types

Link copied to clipboard
entity asset

An asset represents anything that is fungible. It can be more than money, like resources in a game.

Link copied to clipboard
entity balance

Represents an account's holdings of a certain asset.

Link copied to clipboard

Represents the cross-chain movement of an asset on the origin or target chain. No intermediate chain will store this information.

Link copied to clipboard
struct filter

Filter used in queries, which allows to fetch only one direction of transfer

Link copied to clipboard

Details about a transfer. It contains a limited set of information that can be used to describe a transfer_history_entry and a crosschain_transfer_history_entry.

Link copied to clipboard

Represents the movement of an asset in or out of an account.

Link copied to clipboard

The type of a transfer, used for filtering in queries

Properties

Link copied to clipboard
val ASSET_TYPE_FT4: text = "ft4"

The type of fungible assets. By default, assets created with this library will have this asset type. Other libraries that handle assets might have their own types.

Link copied to clipboard

The maximum value that should ever be represented when talking about assets. No balance, transfer, nor total_supply should ever exceed this to maintain compatibility with EVM's int256

Functions

Link copied to clipboard
@extendable function after_burn(account: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the burn function, after the burn happens.

This allows, for example, to check that any given condition is present after the tokens have been burned.

If this function throws an exception, the asset will not be burned.

Throws if any extension of this function throws.

Link copied to clipboard
@extendable function after_mint(account: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the mint function, after the mint happens.

This allows, for example, to check that any given condition is present after the tokens have been minted.

If this function throws an exception, the asset will not be minted.

Throws if any extension of this function throws.

Link copied to clipboard
@extendable function after_transfer(from: account, to: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the transfer function, after the transfer happens.

This allows, for example, to add fees on transfer or check that any given condition is present after the transfer is completed.

If this function throws an exception, the assets will not be transferred.

Throws if any extension of this function throws.

Link copied to clipboard
function Asset(id: byte_array): asset

Returns the asset with the specified id as an entity. Throws "MISSING ASSET" if the asset is not found.

Link copied to clipboard
@extendable function before_burn(account: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the burn function, before the burn happens.

This allows, for example, to check that any given condition is present before burning is allowed.

If this function throws an exception, the asset will not be burned.

Throws if any extension of this function throws.

Link copied to clipboard
@extendable function before_mint(account: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the mint function, before the mint happens.

This allows, for example, to check that any given condition is present before minting is allowed.

If this function throws an exception, the asset will not be minted.

Throws if any extension of this function throws.

Link copied to clipboard
@extendable function before_transfer(from: account, to: account, asset: asset, amount: big_integer)

Extendable function that allows the developer to add more functionality to the transfer function, before the transfer happens.

This allows, for example, to add fees on transfer or check that any given condition is present before the transfer can be completed.

If this function throws an exception, the assets will not be transferred.

Throws if any extension of this function throws.

Link copied to clipboard
@extendable function create_on_internal_transfer(sender: account, recipient_id: byte_array, asset: asset, amount: big_integer)

Extendable function that defines how to create an account when an on-chain transfer to a non-existing account happens.

Developers should not generally extend this function, as it is handled by the account registration module. Importing the corresponding module should be enough.

Link copied to clipboard
function deduct_balance(account: account, asset: asset, amount: big_integer): big_integer

Removes a certain amount of money from an account. It does NOT update total supply, extra care is needed to either decrease it or add the assets to another account.

Only supposed to be called internally, use functions like burn or transfer whenever possible.

Throws "INSUFFICIENT BALANCE" if the amount to be removed is higher than the amount the account holds, or if there's no balance connected to the account and asset given, which means the account has 0 of this asset.

Can only be called from an operation.

Link copied to clipboard
function extract_data_from_transfer_history_entry(entry: transfer_history_entry): (id: rowid, delta: big_integer, decimals: integer, (id: byte_array, name: text, symbol: text, decimals: integer, blockchain_rid: byte_array, icon_url: text, type: text, supply: big_integer), is_input: boolean, timestamp: integer, block_height: integer, tx_rid: byte_array, tx_data: byte_array, operation_name: text, op_index: integer, is_crosschain: boolean)

Maps an entry's info into a readable format for the frontend

Link copied to clipboard

Takes a list of transfer history entries and builds a page that can be returned from paginated queries with it.

Maps a crosschain_transfer_history_entry to a transfer_detail object. This allows some functions to handle both transfer_history_entrys and crosschain_transfer_history_entrys as the same thing.

Maps a transfer_history_entry to a transfer_detail object. This allows some functions to handle both transfer_history_entrys and crosschain_transfer_history_entrys as the same thing.

Link copied to clipboard

Extracts the name of the operation that caused the transfer to happen.

Link copied to clipboard
function format_amount_with_decimals(amount: big_integer, decimals: integer): text

Creates a readable string representing the amount of tokens, given the raw representation of its amount and the decimals.

For example, format_amount_with_decimals(11, 2) will return "0.11"

Throws "INVALID DECIMALS" if decimals is negative.

Link copied to clipboard
function get_all_assets(page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all registered assets, paginated.

Link copied to clipboard
function get_asset_balance(account: account, asset: asset): big_integer

Returns how much of an asset the account holds.

Link copied to clipboard
function get_asset_balances(account_id: byte_array): list<((id: byte_array, name: text, symbol: text, decimals: integer, blockchain_rid: byte_array, icon_url: text, type: text, supply: big_integer), amount: big_integer)>

Retrieves all asset balances for a certain account.

function get_asset_details_for_crosschain_registration(asset_id: byte_array): (id: byte_array, name: text, symbol: text, decimals: integer, blockchain_rid: byte_array, icon_url: text, type: text, uniqueness_resolver: byte_array)

Outputs the details of an asset in a format that is used by other chains to register it as a crosschain asset.

Throws "MISSING ASSET" if the asset does not exist on this chain.

Link copied to clipboard
function get_assets_by_type(type: text, page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all assets of a specified type, paginated.

Link copied to clipboard
function get_paginated_asset_balances(account_id: byte_array, page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all the balances of a certain account, paginated.

Link copied to clipboard
function get_paginated_assets_by_name(name: text, page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all assets with the given name, paginated.

Link copied to clipboard
function get_paginated_assets_by_symbol(symbol: text, page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all assets with the given symbol, paginated.

Link copied to clipboard
function get_paginated_transfers(account: account?, asset: asset?, filter: filter, height: integer?, page_size: integer?, page_cursor: text?): list<pagination_result>

Fetches all transfers, allowing filtering in multiple ways. Paginated.

Link copied to clipboard

Returns a transfer_detail object for each transfer_entry that was registered during the operation specified.

Link copied to clipboard

Same as get_transfer_details, but restricts the results to transfer entries related to the asset specified.

Link copied to clipboard
function increase_balance(account: account, asset: asset, amount: big_integer): big_integer

Adds a certain amount of money to an account. It does NOT update total supply, extra care is needed to either increase it or remove the assets from another account.

Only supposed to be called internally, use functions like mint or transfer whenever possible.

Can only be called from an operation.

Link copied to clipboard

Extendable function that defines whether on-chain transfers towards an account that doesn't exist should be allowed. False by default, can be set to true to allow account registration on transfer.

Developers should not generally extend this function, as it is handled by the account registration module. Importing the corresponding module should be enough.

However, if a custom transfer strategy is going to be implemented, this function could be extended to allow it to work.

Link copied to clipboard
function map_asset(asset: asset): (id: byte_array, name: text, symbol: text, decimals: integer, blockchain_rid: byte_array, icon_url: text, type: text, supply: big_integer)

Maps an asset's info into a readable format for the frontend.

Link copied to clipboard
function parse_icon_url(icon_url: text): text

Tests whether an asset icon URL is invalid. It will not try to resolve the URL, but it will remove trailing and leading whitespace and check that the string looks like an URL.

Throws "INVALID ASSET URL" if the URL is over 2048 characters or it does not match this regex pattern: ^\S+:\/\/[^\s$.?#].[^\s]*$

Link copied to clipboard
@extendable function recall_on_internal_transfer(sender: account, transfer_tx_rid: byte_array, transfer_op_index: integer)

Extendable function that defines how to recall a transfer that was erroneously made toward to a non-existing account, if that account should not be registered.

Developers should not generally extend this function, as it is handled by the account registration module. Importing the corresponding module should be enough.

Ensures that an asset amount is in the interval (0; 2^256) (exclusive)

Throws "INVALID AMOUNT" if value is too high

Throws "INVALID AMOUNT" if value is too low

Should be used inside other functions, and the name parameter should be passed in a way that the error message is understood by the end users.

Example: require_zero_exclusive_asset_amount_limits(-1, "Amount to mint") will throw this error: "INVALID AMOUNT: Amount to mint: value must be non-zero positive, actual: -1"

Link copied to clipboard

Ensures that decimals are in the interval 0; 78 (inclusive)

Throws "INVALID DECIMALS" otherwise.

Link copied to clipboard

Ensures that the ID has exactly 32 bytes

Throws "INVALID ID" otherwise.

Link copied to clipboard
function validate_asset_name(name: text)

Ensures that the text input is at most 1024 characters long.

Throws "INVALID TEXT" otherwise.

Link copied to clipboard
function validate_asset_symbol(symbol: text)

Ensures that the text input is at most 1024 characters long.

Throws "INVALID TEXT" otherwise.

Link copied to clipboard
function validate_asset_type(type: text)

Ensures that the text input is not empty and at most 1024 characters long.

Throws "INVALID TYPE" if type is empty or too long.

Link copied to clipboard

Ensures that the asset uniqueness resolver is at most 1024 bytes long.

Throws "INVALID RESOLVER" otherwise.